import { apiSfctdPage } from '@/api/url/checkModule';
import { mesProFeedBackList } from '@/api/url/linkBase';
import router from '@/router';
import { isParam } from '@/utils/baseMethods';
import { reactive } from 'vue';

export default function importConfig() {
  const base = reactive({
    pagination: {
      defaultPageSize: 10,
      total: 100, //总条数
      current: 1,
      pageSize: 10,
      showTotal: true,
      showPageSize: true,
      pageSizeOptions: [10, 20, 30, 40, 50],
      hideOnSinglePage: true,
    },
    tabelList: null,
  });

  const init = () => {
    getTable();
  };
  const getTable = () => {
    const steam = {
      pageSize: base.pagination.pageSize,
      pageNum: base.pagination.current,
    };
    mesProFeedBackList(steam).then((res: any) => {
      console.log(res, '==>rows');
      if (res.code === 200) {
        base.tabelList = res.rows;
        base.pagination.total = res.total;
      }
    });
  };

  const columns = [
    {
      title: '报工类型',
      dataIndex: 'feedbackType',
    },
    {
      title: '工序',
      dataIndex: 'processName',
    },
    {
      title: '箱号',
      dataIndex: 'xh',
      width: '130',
    },
    {
      title: '生产工单编号',
      dataIndex: 'workorderCode',
    },
    {
      title: '产品物料编码',
      dataIndex: 'itemCode',
    },
    {
      title: '产品物料名称',
      dataIndex: 'itemName',
    },
    {
      title: '规格型号',
      dataIndex: 'specification',
    },
    {
      title: '报工数量',
      dataIndex: 'quantityFeedback',
    },
    {
      title: '上工序',
      dataIndex: 'sgh',
    },
    {
      title: '下工序',
      dataIndex: 'xgh',
    },
    {
      title: '操作员',
      dataIndex: 'czy',
    },
    {
      title: '检验员',
      dataIndex: 'jjy',
    },

    {
      title: '报工时间',
      dataIndex: 'feedbackTime',
    },
    {
      title: '状态',
      dataIndex: 'status',
    },
    {
      title: '操作',
      slotName: 'optional',
    },
  ];

  const collection = reactive([
    { label: '公司名称', value: '', placeholder: '请输入公司名称', isInput: true },
    { label: '创建人', value: '', placeholder: '请输入公司名称', isSelect: true },
    { label: '供应商 ID', value: '', placeholder: '请输入公司名称', isRangePicker: true },
    { label: '供应商名称', value: '', placeholder: '请输入公司名称', isInput: true },
    { label: '负责人', value: '', placeholder: '请输入公司名称', isInput: true },
    { label: '负责人号码', value: '', placeholder: '请输入公司名称', isInput: true },
  ]);

  /**
   * @exports TD010ALL
   * 0.待处理、S.传送中、1.签核中、2.退件、3.已核准、4.撤销审核中、5.作废中、6.取消作废中、N.不运行电子签核
   */
  const TD010ALL = (param?: string | undefined) => {
    const steam: any = [
      {
        value: '0',
        label: '待处理',
      },
      {
        value: 's',
        label: '传送中',
      },
      {
        value: '1',
        label: '签核中',
      },
      {
        value: '2',
        label: '退件',
      },
      {
        value: '3',
        label: '已核准',
      },
      {
        value: '4',
        label: '撤销审核中',
      },
      {
        value: '5',
        label: '作废中',
      },
      {
        value: '6',
        label: '取消作废中',
      },
      {
        value: 'N',
        label: '不运行电子签核',
      },
    ];
    if (param) {
      return isParam(steam, 'value', param).value;
    } else {
      return steam;
    }
  };
  /**
   * @exports TE010ALL
   * 转移类型(1:正常完成 2:返工完成 3:报废 )
   */
  const TE010ALL = (param?: string | undefined) => {
    const steam: any = [
      {
        value: '1',
        label: '正常完成',
      },
      {
        value: '2',
        label: '返工完成',
      },
      {
        value: '3',
        label: '报废',
      },
    ];
    if (param) {
      return isParam(steam, 'value', param).value;
    } else {
      return steam;
    }
  };

  const handlePageChange = (page: number) => {
    base.pagination.current = page;
    init();
  };
  const handlePageSizeChange = (pageSize: number) => {
    base.pagination.pageSize = pageSize;
    init();
  };

  /**
   * @exports viewDetails 查看详情单
   * @param param 品号
   */
  const viewDetails = (param) => {
    // console.log(param)
    router.push({ path: '/inspectionPolicy', query: { td001: param.td001.trim(), td002: param.td002.trim(), te003: param.te003.trim() } });
  };

  /**
   * @exports viewInspect 调起检验单
   */
  const viewInspect = () => {};
  return {
    columns,
    collection,
    handlePageChange,
    handlePageSizeChange,
    base,
    viewDetails,
    viewInspect,
    init,
  };
}
